<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>$(NetCoreAppToolCurrent);$(NetFrameworkToolCurrent)</TargetFrameworks>
    <TargetFramework />
    <Description>MSBuild tasks for running the IL Linker</Description>
    <AutoGenerateAssemblyVersion>true</AutoGenerateAssemblyVersion>
    <!-- To suppress warnings about resetting the assembly version.-->
    <AssemblyVersion />
    <!-- Place illink and cecil alongside ILLink.Tasks in the output, for integration tests. -->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <Nullable>disable</Nullable>
    <IsPackable>true</IsPackable>
    <PackageId>Microsoft.NET.ILLink.Tasks</PackageId>
    <!-- NU5128: This package doesn't contain any lib or ref assemblies because it's a tooling package.
         NU5129: Targets don't match the package id. This is intentional. -->
    <NoWarn>$(NoWarn);NU5128;NU5129</NoWarn>
    <IncludeBuildOutput>false</IncludeBuildOutput>
    <IncludeMultiTargetRoslynComponentTargets>false</IncludeMultiTargetRoslynComponentTargets>
    <TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddBuildOutputToToolsPackage</TargetsForTfmSpecificContentInPackage>
  </PropertyGroup>

  <!-- Include the illink.runtimeconfig.pack.json file (which depends on the runtimeversion being built)
       as illink.runtimeconfig.json in the package, instead of the original illink.runtimeconfig.json. -->
  <Target Name="FixPackageRuntimeConfigPath"
          AfterTargets="AddBuildOutputToToolsPackage"
          Condition="'$(TargetFramework)' == '$(NetCoreAppToolCurrent)'">
    <ItemGroup>
      <TfmSpecificPackageFile Remove="@(TfmSpecificPackageFile)"
                              Condition="$([System.String]::Copy('%(Identity)').EndsWith('.runtimeconfig.json'))" />
      <TfmSpecificPackageFile
        Condition="$([System.String]::Copy('%(TfmSpecificPackageFile.PackagePath)').EndsWith('.pack.json'))"
        PackagePath="$([System.String]::Copy(%(TfmSpecificPackageFile.PackagePath)).Substring(0, $([MSBuild]::Subtract($([System.String]::Copy('%(TfmSpecificPackageFile.PackagePath)').Length), 10)))).json" />
    </ItemGroup>
  </Target>

  <ItemGroup>
    <!-- Note: 'build/Microsoft.NET.ILLink.targets' should not match the package name, because we don't want the targets
         to be imported by nuget. The SDK will import them in the right order. -->
    <Content Include="**\*.props;**\*.targets" Pack="true" PackagePath="%(RecursiveDir)%(Filename)%(Extension)"
             CopyToOutputDirectory="PreserveNewest" TargetPath="%(RecursiveDir)%(Filename)%(Extension)" />
    <Content Include="..\ILLink.RoslynAnalyzer\build\**\*.props" Pack="true" PackagePath="build/%(RecursiveDir)%(Filename)%(Extension)"
             CopyToOutputDirectory="PreserveNewest" TargetPath="build/%(RecursiveDir)%(Filename)%(Extension)" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\ILLink.CodeFix\ILLink.CodeFixProvider.csproj" ReferenceOutputAssembly="false" PackAsAnalyzer="true" />
    <ProjectReference Include="..\ILLink.RoslynAnalyzer\ILLink.RoslynAnalyzer.csproj" ReferenceOutputAssembly="false" PackAsAnalyzer="true" />
    <ProjectReference Include="..\linker\Mono.Linker.csproj" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />

    <PackageReference Include="Microsoft.DotNet.Cecil" Version="$(MicrosoftDotNetCecilVersion)" />
    <PackageReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkVersion)" ExcludeAssets="runtime" />
    <PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCoreVersion)" ExcludeAssets="runtime" />
    <PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataToolsetVersion)" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
  </ItemGroup>

  <ItemGroup>
    <!--
      Update all PackageReference and ProjectReference Items to have
      PrivateAssets="All" and default Publish to true.
      This removes the dependency nodes from the generated nuspec and
      forces the publish output to contain the dlls.
     -->
    <PackageReference Update="@(PackageReference)">
      <PrivateAssets>All</PrivateAssets>
      <Publish Condition="'%(PackageReference.Publish)' == ''">true</Publish>
      <ExcludeAssets Condition="'%(PackageReference.Publish)' == 'false'">runtime</ExcludeAssets>
    </PackageReference>
    <ProjectReference Update="@(ProjectReference)">
      <PrivateAssets>All</PrivateAssets>
      <Publish Condition="'%(ProjectReference.Publish)' == ''">true</Publish>
    </ProjectReference>
  </ItemGroup>

</Project>
